package version1

import (
	"server/global"
	"server/model"
	"server/myutils"

	"github.com/gin-gonic/gin"
)

//@Summary 获取今天的聊天信息(15条)
//@Router /v1/api/gettodychat  [get]
//@Tags Gets
//@Description 无
//@Produce json
//@Accept json
//@Success 200 {object} model.StandardResponse{} `接口被正确调用,但是调用结果看status状态码`
func GetTodayChat(req *gin.Context) {
	//链表取数据
	// b, _ := json.Marshal(gin.H{
	// 	"name":     "忆往昔∝。∝星塵",
	// 	"email":    "705682670@qq.com",
	// 	"avatar":   "https://q4.qlogo.cn/headimg_dl?dst_uin=705682670&spec=100",
	// 	"context":  "有的有的",
	// 	"sendtime": time.Now().Unix(),
	// })
	// model.Redis.LPush(model.Ctx, myutils.Today, b)
	ic := model.Redis.LLen(model.Ctx, myutils.Today)
	if ic.Err() != nil {
		myutils.ResultJSON(req, global.FAIL, nil)
		return
	}
	i, _ := ic.Result()
	if i >= 15 {
		i = 15
	}
	ssc := model.Redis.LRange(model.Ctx, myutils.Today, 0, i)
	s, _ := ssc.Result()
	myutils.ResultJSON(req, global.SUCCESS, s)
}
